﻿using System.Collections.ObjectModel;
using System.Windows;
using Rio.Framework.Localisation;
using Telerik.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace Rio.Framework.Pages.ChildWindows
{
    public partial class BarcodeResultChildWindow : RadWindow
    {

        /// <summary>
        /// Gets or sets the folders.
        /// </summary>
        /// <value>The folders.</value>
        public ObservableCollection<Rio.Framework.Pages.Manager.BarcodeManager.FolderDataContext> Folders
        {
            get
            {
                return (ObservableCollection<Rio.Framework.Pages.Manager.BarcodeManager.FolderDataContext>)this.GetValue(FoldersProperty);
            }
            set
            {
                this.SetValue(FoldersProperty, value);
            }
        }
        public static readonly DependencyProperty FoldersProperty =
        DependencyProperty.Register("Folders", typeof(ObservableCollection<Rio.Framework.Pages.Manager.BarcodeManager.FolderDataContext>), typeof(BarcodeResultChildWindow), null);

        /// <summary>
        /// Initializes a new instance of the <see cref="BarcodeResultChildWindow" /> class.
        /// </summary>
        public BarcodeResultChildWindow()
        {
            this.InitializeComponent();
            this.InitLabels();          
        }

        /// <summary>
        /// Inits the labels.
        /// </summary>
        private void InitLabels()
        {
            this.TextBlockToIndex.Text = Resx.GetLabel(ResxIndexPanel.TOINDEX);
            this.CancelBtn.Content = Resx.GetLabel(ResxCommon.CANCEL);
            this.Header = Resx.GetLabel(ResxCommon.BARCODE_RESULT_WINDOW_TITLE);
        }

        /// <summary>
        /// Handles the Click event of the OkBtn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void OkBtn_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        /// <summary>
        /// Handles the Click event of the CancelBtn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        /// <summary>
        /// Handles the Loaded event of the RadWindow control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void RadWindow_Loaded(object sender, RoutedEventArgs e)
        {
        }

        /// <summary>
        /// Handles the KeyUp event of the radWindow control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.KeyEventArgs" /> instance containing the event data.</param>
        private void radWindow_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                this.DialogResult = false;
                this.Close();
            }
            else if(e.Key == Key.Enter)
            {
                this.DialogResult = true;
                this.Close();
            }
        }

        /// <summary>
        /// Handles the ItemPrepared event of the TreeView control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Telerik.Windows.Controls.RadTreeViewItemPreparedEventArgs" /> instance containing the event data.</param>
        private void TreeView_ItemPrepared(object sender, RadTreeViewItemPreparedEventArgs e)
        {
            var treeViewItem = e.PreparedItem;
            if (treeViewItem.Level == 0)
            {
                treeViewItem.IsExpanded = true;
            }
        }

    }
}